#include "comm.h"
int main(){
  key_t key = ftok(PATH_NAME, PROJ_ID);
  if(key < 0){
    perror("ftok");
    return 1;
  }

  int shmId = shmget(key, SIZE,IPC_CREAT | IPC_EXCL | 0666);//创建全新的shm，如果和系统已经存在ID冲突，就出错返回
  if(shmId < 0){
    perror("shmget");
    return 2;
  }
  printf("key->%u, shmId->%d\n", key, shmId);
  //sleep(1);
  
  char* mem = (char*)shmat(shmId, NULL, 0);//建立关联
  printf("attaches shm success\n");
  //sleep(15);

  //开始逻辑实现的部分
  while(1){
    sleep(1);
    printf("%s\n", mem);
  }  


  shmdt(mem);//去关联
  printf("detaches shm success\n");

  shmctl(shmId, IPC_RMID, NULL);
  //sleep(5);
  
  printf("key->0x%u, shmId->%d   shm delete success\n", key, shmId);
  //sleep(10);

  return 0;
}
